#include "list.h"

VarList::VarList(Id * name): AbstractNode()
{
	c_names.push_back(name);
}


void VarList::add(Id * name)
{ 
	c_names.push_back(name); 
}

void VarList::write(GraphStream * s)
{
	this->accept(s);

	fprintf(s->stream,"\tnode_%d [ label=\"defenition variables\" shape=\"rectangle\"]\n",this->number());
	for(unsigned int i=0;i<c_names.size();i++) {
		c_names[i]->write(s);
		fprintf(s->stream, "\tnode_%d -> node_%d\n",this->number(),c_names[i]->number());
	}
}

VarList::~VarList()
{
	for (unsigned int i=0;i<c_names.size();i++) {
		delete c_names[i];
	}	
}

MethodVarList::MethodVarList(Expression * name) : AbstractNode()
{
	c_names.push_back(name);
}

MethodVarList::MethodVarList(Expression * name , Id * param) : AbstractNode()
{
	c_names.push_back(name);
	c_params.push_back(param);
}

void MethodVarList::add(Expression * name , Id * param)
{
	c_names.push_back(name);
	c_params.push_back(param);
}

void MethodVarList::write(GraphStream * s)
{
	this->accept(s);

	fprintf(s->stream,"\tnode_%d [ label=\"method names and params\" shape=\"rectangle\"]\n",this->number());
	for(unsigned int i=0;i<c_names.size();i++) {
		c_names[i]->write(s);
		fprintf(s->stream, "\tnode_%d -> node_%d [label=\"name\"]\n",this->number(),c_names[i]->number());
	}
	for(unsigned int i=0;i<c_params.size();i++) {
		c_params[i]->write(s);
		fprintf(s->stream, "\tnode_%d -> node_%d [label=\"param\"]\n",this->number(),c_params[i]->number());
	}
}

MethodVarList::~MethodVarList()
{
	for (unsigned int i=0;i<c_names.size();i++) {
		delete c_names[i];
	}	
	for (unsigned int i=0;i<c_params.size();i++) {
		delete c_params[i];
	}	
}

